package com.ruoyi.project.tickets.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tickets.domain.TicketsRule;
import com.ruoyi.project.tickets.service.ITicketsRuleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 票券规则Controller
 * 
 * @author 孙山伟
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/tickets/rule")
public class TicketsRuleController extends BaseController
{
    @Autowired
    private ITicketsRuleService ticketsRuleService;

    /**
     * 查询票券规则列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketsRule ticketsRule)
    {
        startPage();
        List<TicketsRule> list = ticketsRuleService.selectTicketsRuleList(ticketsRule);
        return getDataTable(list);
    }
    @GetMapping("/listAllRule")
    public AjaxResult listAllRule(TicketsRule ticketsRule)
    {
        List<TicketsRule> list = ticketsRuleService.selectTicketsRuleList(ticketsRule);
        return AjaxResult.success(list);
    }
    /**
     * 导出票券规则列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:rule:export')")
    @Log(title = "票券规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TicketsRule ticketsRule)
    {
        List<TicketsRule> list = ticketsRuleService.selectTicketsRuleList(ticketsRule);
        ExcelUtil<TicketsRule> util = new ExcelUtil<TicketsRule>(TicketsRule.class);
        return util.exportExcel(list, "rule");
    }

    /**
     * 获取票券规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('tickets:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ticketsRuleService.selectTicketsRuleById(id));
    }

    /**
     * 新增票券规则
     */
    @PreAuthorize("@ss.hasPermi('tickets:rule:add')")
    @Log(title = "票券规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketsRule ticketsRule)
    {
        return toAjax(ticketsRuleService.insertTicketsRule(ticketsRule));
    }

    /**
     * 修改票券规则
     */
    @PreAuthorize("@ss.hasPermi('tickets:rule:edit')")
    @Log(title = "票券规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketsRule ticketsRule)
    {
        return toAjax(ticketsRuleService.updateTicketsRule(ticketsRule));
    }

    /**
     * 删除票券规则
     */
    @PreAuthorize("@ss.hasPermi('tickets:rule:remove')")
    @Log(title = "票券规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ticketsRuleService.deleteTicketsRuleByIds(ids));
    }
}
